#include "RawSoundPlot.h"


RawSoundPlot::RawSoundPlot(SoundObj *so, long channel, QWidget * parent) : QwtPlot(parent)
{
	QwtPainter::setDeviceClipping(false);

	// Insert one curve and get ID for it
	QwtPlotCurve * curve = new QwtPlotCurve();
	curve->setRenderHint(QwtPlotItem::RenderAntialiased);

	// Calculate the data
	const long size = so->getDataSize();

	double *x;
	double *y;

	x = new double[size];
	y = new double[size];

	for(long i=0; i<size; i++)
	{
		x[i] = i;
		y[i] = (double) (so->getDataByBits(channel, i));
	}

	// Copy the data to the plot
	curve->setData(x, y, size);

	// Set the style of the curves
	curve->setPen(QPen(Qt::red));
	curve->attach(this);
}

void RawSoundPlot::alignScales()
{
	canvas()->setFrameStyle(QFrame::Box | QFrame::Plain );
	canvas()->setLineWidth(1);

	for (long i=0; i<QwtPlot::axisCnt; i++)
	{
		QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(i);
		if (scaleWidget) scaleWidget->setMargin(0);

		QwtScaleDraw *scaleDraw = (QwtScaleDraw *)axisScaleDraw(i);

		if (scaleDraw)
		{
			scaleDraw->enableComponent(QwtAbstractScaleDraw::Backbone, false);
		}
	}
}

RawSoundPlot::~RawSoundPlot()
{

}
